package com.lingnan.util;

import com.lingnan.service.NotificationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

// NotificationUtil.java
@Component
@Slf4j
public class NotificationUtil {
    
    @Autowired
    private NotificationService notificationService;
    
    /**
     * 发送简历状态通知
     */
    public void sendResumeStatusNotification(Long receiverId, String companyName, String position, String status) {
        String title = "简历状态更新";
        String content = String.format("您投递给 %s 的 %s 职位，简历状态已更新为：%s", companyName, position, status);
        notificationService.sendPersonalNotification(null, receiverId, title, content, 3);
    }
    
    /**
     * 发送面试邀请通知
     */
    public void sendInterviewInvitation(Long senderId, Long receiverId, String companyName, String position, String interviewTime, String address) {
        String title = "面试邀请";
        String content = String.format("恭喜！%s 邀请您参加 %s 职位的面试。\n面试时间：%s\n面试地址：%s", 
                companyName, position, interviewTime, address);
        notificationService.sendPersonalNotification(senderId, receiverId, title, content, 2);
    }
    
    /**
     * 发送系统维护公告
     */
    public void sendMaintenanceAnnouncement(Long adminId, String maintenanceTime, String duration) {
        String title = "系统维护通知";
        String content = String.format("系统将于 %s 进行维护，预计耗时 %s，期间服务可能暂停，请提前做好准备。", maintenanceTime, duration);
        notificationService.sendSystemAnnouncement(adminId, title, content);
    }
    
    /**
     * 发送新职位推荐
     */
    public void sendJobRecommendation(Long receiverId, String jobTitle, String companyName, String salary) {
        String title = "职位推荐";
        String content = String.format("为您推荐新职位：%s - %s，薪资：%s", jobTitle, companyName, salary);
        notificationService.sendPersonalNotification(null, receiverId, title, content, 1);
    }
    
    /**
     * 发送企业认证结果通知
     */
    public void sendCompanyVerificationResult(Long receiverId, String companyName, boolean approved, String reason) {
        String title = "企业认证结果";
        String content = approved ? 
                String.format("恭喜！您的企业 %s 已通过认证，可以正常发布职位了。", companyName) :
                String.format("很抱歉，您的企业 %s 认证未通过。原因：%s", companyName, reason);
        notificationService.sendPersonalNotification(null, receiverId, title, content, 0);
    }
    
    /**
     * 发送黑名单警告
     */
    public void sendBlacklistWarning(Long receiverId, String reason) {
        String title = "账号警告";
        String content = String.format("您的账号因 %s 被举报，请注意规范使用平台功能。", reason);
        notificationService.sendPersonalNotification(null, receiverId, title, content, 0);
    }

    /**
     * 发送新聊天消息通知
     */
    public void sendNewMessageNotification(Long senderId, Long receiverId, String senderName, String messagePreview) {
        String title = "新聊天消息";
        String content = String.format("%s: %s", senderName, messagePreview);
        notificationService.sendPersonalNotification(senderId, receiverId, title, content, 4); // 类型4表示聊天消息
    }
}